//
//  HWCommenCell.m
//  嗨文
//
//  Created by 响当当 on 2019/1/17.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWCommenCell.h"

@interface HWCommenCell()
@property (nonatomic, strong)UIImageView *headImageView;//头像
@property (nonatomic, strong)UILabel *titleLabel;//名字
@property (nonatomic, strong)UIImageView *haiFriendImageView;//嗨书友
@property (nonatomic, strong)UIImageView *vipImageView;//VIP
@property (nonatomic, strong)UILabel *contextLabel;//评论内容
@property (nonatomic, strong)UILabel *timeLabel;//时间
@property (nonatomic, strong)UILabel *bookNameLabel;//书名
@property (nonatomic, strong)UIButton *hwLevelButton;//嗨等级
@property (nonatomic, strong)UIView *lineView;//下划线
@property (nonatomic, strong)UIImageView *topImageView;//置顶
@property (nonatomic, strong)UIImageView *aplyImageView;//申精
@end

@implementation HWCommenCell
- (UIImageView *)headImageView
{
    if (!_headImageView)
    {
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,15*kUIScaleBasePlus,30*kUIScaleBasePlus,30*kUIScaleBasePlus)];
    }
    return _headImageView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+15*kUIScaleBasePlus,23*kUIScaleBasePlus,0,15*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0x828282)
                                             textFont:16*kUIScaleBasePlus];
        
    }
    return _titleLabel;
}

- (UIImageView *)haiFriendImageView
{
    if (!_haiFriendImageView)
    {
        _haiFriendImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,25*kUIScaleBasePlus,36*kUIScaleBasePlus,11*kUIScaleBasePlus)];
    }
    return _haiFriendImageView;
}

- (UIImageView *)vipImageView
{
    if (!_vipImageView)
    {
        _vipImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,25*kUIScaleBasePlus,27*kUIScaleBasePlus,11*kUIScaleBasePlus)];
    }
    return _vipImageView;
}

- (UIButton *)hwLevelButton
{
    if (!_hwLevelButton)
    {
        _hwLevelButton = [HWUtilties creatButtonWithFrame:CGRectMake(244*kUIScaleBasePlus,18*kUIScaleBasePlus,62*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentRight
                                                     text:@"嗨赚Lv32"
                                                 textClor:[UIColor whiteColor]
                                                buttonBGC:[UIColor clearColor]
                                                 textFont:12*kUIScaleBasePlus
                                                   target:self
                                                   method:nil];
        [_hwLevelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:9*kUIScaleBasePlus]];
        _hwLevelButton.enabled = NO;
        [_hwLevelButton setBackgroundImage:[UIImage imageNamed:@"earn_level"] forState:UIControlStateNormal];
        [_hwLevelButton setTitleEdgeInsets:UIEdgeInsetsMake(3,0,0,-15)];
    }
    return _hwLevelButton;
}

- (UIImageView *)aplyImageView
{
    if (!_aplyImageView)
    {
        _aplyImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-30*kUIScaleBasePlus,23*kUIScaleBasePlus,15*kUIScaleBasePlus,15*kUIScaleBasePlus)];
    }
    return _aplyImageView;
}

- (UIImageView *)topImageView
{
    if (!_topImageView)
    {
        _topImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-50*kUIScaleBasePlus,23*kUIScaleBasePlus,15*kUIScaleBasePlus,15*kUIScaleBasePlus)];
    }
    return _topImageView;
}

- (UILabel *)contextLabel
{
    if (!_contextLabel)
    {
        _contextLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+15*kUIScaleBasePlus,CGRectGetMaxY(self.titleLabel.frame)+18*kUIScaleBasePlus,301*kUIScaleBasePlus,0)
                                           textAligment:NSTextAlignmentLeft
                                               textClor:LCHexColor(0x545454)
                                               textFont:14*kUIScaleBasePlus];
        _contextLabel.numberOfLines = 0;
    }
    return _contextLabel;
}

- (UILabel *)timeLabel
{
    if (!_timeLabel)
    {
        _timeLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+15*kUIScaleBasePlus,0,125*kUIScaleBasePlus,9*kUIScaleBasePlus)
                                        textAligment:NSTextAlignmentLeft
                                            textClor:LCHexColor(0xA1A1A1)
                                            textFont:12*kUIScaleBasePlus];
    }
    return _timeLabel;
}

- (UILabel *)bookNameLabel
{
    if (!_bookNameLabel)
    {
        _bookNameLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,0,0,12*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentRight
                                                textClor:LCHexColor(0xA1A1A1)
                                                textFont:12*kUIScaleBasePlus];
    }
    return _bookNameLabel;
}

- (UIView *)lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,self.frame.size.height-1*kUIScaleBasePlus,345*kUIScaleBasePlus,1*kUIScaleBasePlus)];
        _lineView.backgroundColor = LCHexColor(0xEBE5E1);
    }
    return _lineView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.headImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.haiFriendImageView];
        [self.contentView addSubview:self.vipImageView];
        [self.contentView addSubview:self.hwLevelButton];
//        [self.contentView addSubview:self.topImageView];
//        [self.contentView addSubview:self.aplyImageView];
        [self.contentView addSubview:self.contextLabel];
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:self.bookNameLabel];
        [self.contentView addSubview:self.lineView];

    }
    return self;
}

#pragma mark - 获取每行的高度
- (CGFloat)getBackRowHeight:(HWCommentModel *)model
{
    CGFloat height = 0;
    self.contextLabel.text = model.content;
    [self.contextLabel sizeToFit];
    height = self.contextLabel.frame.size.height + (23+15+18+18+9+20)*kUIScaleBasePlus;
    return height;
}

#pragma mark - 获取评论数据
- (void)getCommentDate:(HWCommentModel *)model
{
    
    self.headImageView.image = [model.commentorHeadImg isValidString] ? [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.commentorHeadImg]]] : [UIImage imageNamed:@"head_normal"];

    
    self.titleLabel.text = model.commentorName;
    [self.titleLabel sizeToFit];
    
    [self.haiFriendImageView setX:CGRectGetMaxX(self.titleLabel.frame)+10*kUIScaleBasePlus];
    self.haiFriendImageView.image = [UIImage imageNamed:@"book_friend"];
    
    if ([model.isVip isValidString])
    {
        self.vipImageView.image = [UIImage imageNamed:@"vip_nactive"];
    }
    else
    {
        self.vipImageView.image = [UIImage imageNamed:@"vip_nonactive"];
    }
    [self.vipImageView setX:CGRectGetMaxX(self.titleLabel.frame)+56*kUIScaleBasePlus];
    
    [self.hwLevelButton setX:CGRectGetMaxX(self.titleLabel.frame)+92*kUIScaleBasePlus];
    
//    self.topImageView.image = [UIImage imageNamed:@"top_apex"];
//    self.aplyImageView.image = [UIImage imageNamed:@"top_essence"];

    self.contextLabel.text = model.content;
    [self.contextLabel sizeToFit];
    
    self.timeLabel.text = [HWUtilties getTime:model.createTime];
    [self.timeLabel setY:CGRectGetMaxY(self.contextLabel.frame)+18*kUIScaleBasePlus];
    
    self.bookNameLabel.text = model.bookName;
    [self.bookNameLabel sizeToFit];
    [self.bookNameLabel setX:SCREEN_WIDTH-15*kUIScaleBasePlus-self.bookNameLabel.frame.size.width];
    [self.bookNameLabel setY:CGRectGetMaxY(self.contextLabel.frame)+18*kUIScaleBasePlus];
    
    [self.lineView setY:CGRectGetMaxY(self.timeLabel.frame)+18*kUIScaleBasePlus];
}
@end
